package de.bensoft.jrail.server.impl.service;

import de.bensoft.jrail.server.api.service.LocomotiveServiceInterface;
import de.bensoft.server.model.entity.Locomotive;

import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.util.List;

/**
 * **************************************************
 * ***        THIS FILE IS COPYRIGHT BY          ****
 * ***              Michael Benoit               ****
 * **************************************************
 * User: michael
 * Date: 15.11.13
 * Time: 17:42
 */
@Stateless
@Path("/LocomotiveService")
@Produces("application/xml")
public class LocomotiveService implements LocomotiveServiceInterface {

    @PersistenceContext
    private EntityManager entityManager;

    @GET
    @Override
    @Path("/getAllLocos")
    public List<Locomotive> getAllLocomotives() {
        Query q = entityManager.createNamedQuery(Locomotive.GET_ALL_LOCOMOTIVES);
        return q.getResultList();
    }
}
